﻿using System;
using System.Windows.Forms;
using GameLogic;

namespace Interface
{
    public partial class NewPlayerForm : Form
    {
        private readonly IUserStorage storage;

        public NewPlayerForm(IUserStorage storage)
        {
            this.storage = storage;
            InitializeComponent();
        }

        private void CreateNewPlayerBtnClick(object sender, EventArgs e)
        {
            string name = playerName_txtBx.Text;
            var user = new User();
            if (name.Length!=0)
                user.Name = name;
            try
            {
                storage.SaveUser(user);
                Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Error!");
            }                       
        }


    }
}
